<template>
  <div class="person c-shadow">
    <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" class="demo-ruleForm form">
      <h4 class="detail-base-title">个人信息</h4>
      <div class="formpart">
        <p class="inputs">
          <label for="users">用户名</label>
          <input type="text" v-model.number="ruleForm2.users" disabled>
        </p>
        <p class="inputs">
          <label for="name">姓名</label>
          <input type="text" v-model.number="ruleForm2.name" disabled>
        </p>
        <p class="inputs">
          <label for="phone">手机号</label>
          <input type="text" v-model.number="ruleForm2.phone">
        </p>
        <p class="inputs">
          <label for="email">邮箱</label>
          <input type="text" v-model.number="ruleForm2.email">
        </p>
      </div>
      <h4 class="detail-base-title">公司信息</h4>
      <div class="formpart">
        <p class="inputs">
          <label for="department">公司部门</label>
          <input type="text" v-model.number="ruleForm2.department" disabled>
        </p>
        <p class="inputs">
          <label for="department1">部门</label>
          <input type="text" v-model.number="ruleForm2.department1" disabled>
        </p>
        <p class="inputs">
          <label for="role">角色</label>
          <input type="text" v-model.number="ruleForm2.role" disabled>
        </p>
        <p class="inputs">
          <label for="position">职位</label>
          <input type="text" v-model.number="ruleForm2.position" disabled>
        </p>
        <p class="buttons">
          <button type="submit" class="el-button el-button-primary" @click="submitForm('ruleForm2')">保存</button>
        </p>
      </div>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    var validatePhone = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入手机号'))
      } else {
        var myreg=/^[1][3,4,5,7,8][0-9]{9}$/
        if (!myreg.test(value)) {
          callback(new Error('请输入正确的手机号'))
        } else {
          callback()
        }
      }
    }
    var validateEmail = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入邮箱'))
      } else {
        if (value.matches("^[a-z0-9A-Z]+[- | a-z0-9A-Z . _]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$")) {
          callback()
        } else {
          callback(new Error('请输入正确的邮箱'))
        }
      }
    }
    return {
      ruleForm2: {
        pass: '',
        checkPass: '',
        users: '',
        name: '',
        phone: '',
        email: ''
      },
      rules2: {
        phone: [
          { validator: validatePhone, trigger: 'blur' }
        ],
        email: [
          { validator: validateEmail, trigger: 'blur' }
        ]
      }
    }
  },
  mounted() {
    // this.ruleForm2.users = this.$route.query.entname
    // this.ruleForm2.name = this.$route.query.name
    // this.ruleForm2.department = this.$route.query.department
    // this.ruleForm2.department1 = this.$route.query.department1
    // this.ruleForm2.role = this.$route.query.role
    // this.ruleForm2.position = this.$route.query.position
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log('submit')
        } else {
          console.log('error')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
.person {
  width: 100%;
  height: auto;
  padding: 30px 40px;
  .form {
    width: 90%;
  }
  .inputs {
    height: 35px;
    line-height: 35px;
    padding: 10px 20px;
    label {
      width: 80px;
      display: inline-block;
      text-align: left;
      margin-right: 10px;
    }
    input {
      width: 50%;
      border: 1px solid #999;
      height: 100%;
    }
  }
  .buttons {
    text-align: center;
    padding: 10px 20px;
    button {
      width: 150px;
    }
  }
  .formpart {
    width: 50%;
    margin: 0 auto;
  }
  .el-input {
    width: auto;
  }
  .detail-base-title {
    font-size: 16px;
    font-weight: bold;
    border-bottom: 1px solid #ccc;
    padding: 12px 0;
    margin-bottom: 25px;
  }
}
</style>


// WEBPACK FOOTER //
// src/view/sysManage/personinformation.vue